/**
 * 
 */
package tests;


import java.sql.ResultSet;
import java.util.ArrayList;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import com.davinci.freemarket.dataAccessLayer.accessdata.user.UserDAO;
import com.davinci.freemarket.dataModelLayer.model.DBAttibuteModel;
import com.microsoft.sqlserver.jdbc.SQLServerException;

/**
 * @author Lucas Buyo
 *
 */
public class UserUnitTesting
{

	/**
	 * @throws java.lang.Exception
	 */
	@BeforeClass
	public static void setUpBeforeClass() throws Exception {
	}

	/**
	 * @throws java.lang.Exception
	 */
	@AfterClass
	public static void tearDownAfterClass() throws Exception {
	}

	/**
	 * @throws java.lang.Exception
	 */
	@Before
	public void setUp() throws Exception {
	}

	/**
	 * @throws java.lang.Exception
	 */
	@After
	public void tearDown() throws Exception {
	}
	
	@Test
	public void selectUsers(){
		UserDAO userdao = new UserDAO();
		
		ArrayList<DBAttibuteModel> conditions = new ArrayList<DBAttibuteModel>();
		conditions.add(new DBAttibuteModel("EMAIL", "lucasbuyo@gmail.com"));
		conditions.add(new DBAttibuteModel("PASS", "Muma"));
		/*
		conditions.add(new DBAttibuteModel("NICK", "%Updt%"));
		conditions.add(new DBAttibuteModel("PASS", "%Updt%"));
		conditions.add(new DBAttibuteModel("EMAIL", "%Updt%"));
		conditions.add(new DBAttibuteModel("DIRECCION", "%Updt%")); */
		
		ResultSet rs = userdao.selectUsers(conditions, null);
		Assert.assertTrue(rs != null);
		String result = "";
		try {
			while (rs.next()) {
				result += rs.getString(1) + ", " + rs.getString(2) + ", " +rs.getString(3) + ", " +rs.getString(4) + ", " +rs.getString(5)+ ", " +rs.getString(6)+ ", " +rs.getString(7);
			}
			System.out.println(result);
		}
		catch (SQLServerException e) {
			System.out.println(e);
		}
		catch (Exception e) {
			System.out.println(e);
		}
		
		userdao.closeConnection();
	}
	
	@Test
	public void addUser(){
		UserDAO userdao = new UserDAO();
		int rs = userdao.addUser("nickTest", "passTest", "emailTest", "addressTest", "nameTest", "lastnameTest", "phoneTest");
		Assert.assertTrue(rs != 0);
	}
	
	@Test
	public void modifyUser(){
		UserDAO userdao = new UserDAO();
		int rs = userdao.modifyUser(11, "nickUpdtTest", "passUpdtTest", "emailUpdtTest", "addressUpdtTest", "nameUpdtTest", "lastnameUpdtTest", "phoneUpdtTest");
		Assert.assertTrue(rs != 0);
	}
	
	@Test
	public void deleteUser(){
		UserDAO userdao = new UserDAO();
		int rs = userdao.deleteUser(17);
		Assert.assertTrue(rs != 0);
	}
	
	
	

}
